from bs4 import BeautifulSoup
import requests
import json


def get_osu_info(user_name='ygywzb', url='https://osu.ppy.sh/users/'):
    wb_data = requests.get(url + user_name)
    soup = BeautifulSoup(wb_data.text, 'lxml')
    temp = soup.find('div', class_='js-react--profile-page osu-layout osu-layout--full')
    try:
        src_str = temp.get("data-initial-data")
        src_json = json.loads(src_str)
        d1_res = src_json['user']['statistics']
        d1_res['username'] = src_json['user']['username']
        d1_res['id'] = src_json['user']['id']
        d1_res['playmode'] = src_json['user']['playmode']
        return d1_res
    except AttributeError:
        return None


get_osu_info('ygywzb')